package com.xnyzc.lhy.resource.util.worksheet;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptTool {
	public static EncryptTool encryptTool;
	public static EncryptTool getInstance(){
		if(null == encryptTool){
			synchronized (EncryptTool.class) {
				if(null == encryptTool) {
					encryptTool = new EncryptTool();
				}
			}
		}
		return encryptTool;
	}

	/**
     * md5 加密
     * @param input
     * @return
     */
    public String md5(String input) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
        }

        md.update(input.getBytes());
        byte byteData[] = md.digest();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            buffer.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        return buffer.toString();
    }
}
